package com.gca.airhockey;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsConnector;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.Contact;
import com.badlogic.gdx.physics.box2d.ContactImpulse;
import com.badlogic.gdx.physics.box2d.ContactListener;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.Manifold;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.Log;

public class Goal implements IPhysicalObject{
	private static final String BUT_IMAGE = "gfx/goal.png";

	private BitmapTextureAtlas mTexture;
	private TextureRegion mRegion;
	private Body mBody;
	private Sprite mSprite;

	// ===========================================================
	// Constructors
	// ===========================================================
	public Goal(Context pContext, Engine engine,PhysicsWorld physicsWorld, ESide pSide) {
		
		this.mTexture = new BitmapTextureAtlas(2, 256,
				TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.mRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				this.mTexture, pContext, BUT_IMAGE, 0, 0);
		engine.getTextureManager().loadTexture(this.mTexture);
		
		int posY = 252;
		int posX;
		if(pSide == ESide.LEFT)
			posX = 10;
		else
			posX = 1280-10;
		
		
		this.mSprite = new Sprite(posX, posY, mRegion);
	
		final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(1, 1f, 0);
	
		mBody = PhysicsFactory.createCircleBody(physicsWorld, mSprite, BodyType.StaticBody, objectFixtureDef);
		mBody.setUserData(this);
		physicsWorld.registerPhysicsConnector(new PhysicsConnector(mSprite, mBody, true, true));
						
	}

	// ===========================================================
	// Getters and Setters
	// ===========================================================
	public Sprite getSprite() {
		return mSprite;
	}
	public Body getBody() {                                                                                                                                                                                
		return mBody;
	}
	
	@Override
	public String toString() {
		return "Goal";
	}
}
